package com.example.mysecondapp;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;

public class ListA extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstance) {
    	super.onCreate(savedInstance);
          setContentView(R.layout.list_example);

          // some code

//          Cursor cursor = getContentResolver().query(People.CONTENT_URI, new String[] {People._ID, People.NAME, People.NUMBER}, null, null, null);
//          startManagingCursor(cursor);
          
//  		String[] col = new String[3];
//  		col[0]="_id";
//  		col[1]="col1";
//  		col[2]="col2";
//  		MatrixCursor cursor = new MatrixCursor(col);
//  		String[] val1 = new String[3];
//  		val1[0]="11";
//  		val1[1]="val12dddddddddddddddddddddddddddddddddddddddddddddddddddddd";
//  		val1[2]="val13eeeeeeeeeeeeeeeeeewewwwwwwwwwwwwwrrrrrrrrrrrttttttttt";
//  		String[] val2 = new String[3];
//  		val2[0]="21";
//  		val2[1]="val22ddffffffffffffffffffffffffffffffffffffffffffffffffff";
//  		val2[2]="val23ddddddddddddddddddddffffffggggggggggggggggggghhhhhhhhh";
//  		String[] val3 = new String[3];
//  		val3[0]="31";
//  		val3[1]="val32ttttttttttttttttttttttggggggggggggggggggggggggggggggggggggg";
//  		val3[2]="val33sssssssssssssssssssssffffffffffffffffffffffffffffffffffff";	
//  		
//  		cursor.addRow(val1);
//  		cursor.addRow(val2);
//  		cursor.addRow(val3); 
//  		
         Cursor cursor;  
         cursor = this.getTestCursor(40,12);

          // the desired columns to be bound
          String[] columns = new String[] { "col1", "col2", "col3", "col4", "col5", "col6","col7","col8","col9" };
          // the XML defined views which the data will be bound to
          int[] to = new int[] { R.id.col1,R.id.col2,R.id.col3,R.id.col4,R.id.col5,R.id.col6,R.id.col7,R.id.col8,R.id.col9 };

          // create the adapter using the cursor pointing to the desired data as well as the layout information
         // SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_example_entry, cursor, columns, to);
          
          SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.linealvertical, cursor, columns, to, 0);

          // set this adapter as your ListActivity's adapter
          this.setListAdapter(adapter);
    }
    
    public Cursor getTestCursor(int filas, int columnas){
    	String[] nameCols = new String[columnas+1];//+1 por el campo _id
    	nameCols[0]="_id";
    	String[][] data = new String[columnas+1][filas];
    	for(int co =0;co<=columnas;co++){
    		if(co==0){nameCols[0]="_id";}else{nameCols[co]="col"+co;}
    		for(int fi =0;fi<filas;fi++){
    			if(co==0){data[co][fi]=""+co+fi;}else{data[co][fi]="val col="+co+" fi="+fi;}		
    		}
    	}
    	MatrixCursor cursor = new MatrixCursor(nameCols);
    	for(int fi =0;fi<filas;fi++){
    		String[] temp = new String[columnas+1];
    		for(int co =0;co<=columnas;co++){
    			temp[co]= data[co][fi];
    		}
    		cursor.addRow(temp);
    	}    	
		return cursor;	
    }
}

